package com.lagou.seckill.listen;

import com.lagou.seckill.constant.Constants;
import com.lagou.seckill.constant.StatusEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
@RocketMQMessageListener(consumerGroup = Constants.CONSUMER_GROUP + Constants.ORDER_TOPIC, topic = Constants.ORDER_TOPIC)
public class OrderListener implements RocketMQListener<String> {

    final RedisTemplate redisTemplate;

    public void onMessage(String order) {
        log.info("收到订单信息:{}", order);
        redisTemplate.opsForValue().setIfPresent(order, StatusEnum.TOBE_PAY.code);
        log.info("订单[{}]下单成功,待支付...", order);
    }
}
